﻿/*!
   A C-program for MT19937, with initialization improved 2002/1/26.
   Coded by Takuji Nishimura and Makoto Matsumoto.

   Before using, initialize the state by using init_genrand(seed)
   or init_by_array(init_key, key_length).

   Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,
   All rights reserved.
   Copyright (C) 2005, Mutsuo Saito
   All rights reserved.

   Redistribution and use in source and binary forms, with or without
   modification, are permitted provided that the following conditions
   are met:

     1. Redistributions of source code must retain the above copyright
        notice, this list of conditions and the following disclaimer.

     2. Redistributions in binary form must reproduce the above copyright
        notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.

     3. The names of its contributors may not be used to endorse or promote
        products derived from this software without specific prior written
        permission.

   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


   Any feedback is very welcome.
   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
   email: m-mat @ math.sci.hiroshima-u.ac.jp (remove space)

	Modified from mt19937ar.h	2009/12/6	Yuya Yamaguchi
	このソースコードはメルセンヌツイスターのコードをc++にリライトしたものです。
	再配布はオリジナルのライセンスに基づき行われます。
*/


#ifndef _R_MT19937AR_H_
#define _R_MT19937AR_H_

#include "../rtti/r_rtti_class_base.h"

namespace r{
	namespace math{
		#define RMT19937AR_N 624

		class MT19937AR : public r::rtti::ClassBase
		{
			RRTTI_REFLECTION_DECLARE
		public:
			///
			MT19937AR();
		public:
			//! キーで初期化
			MT19937AR ( r_ui32 s );
			//! 配列で初期化
			MT19937AR ( r_ui32 init_key[], r_si32 key_length );
		public:
			//! 乱数生成:0～0xffffffff
			r_ui32 genrand_int32 ( void );
			//! 乱数生成:0～0x7fffffff
			r_si32 genrand_int31 ( void );
			//! 乱数生成:-1.0f～1.0f
			/*! オリジナルはdouble...
			*/
			r_f32	genrand_f32 ( void );
			//! 乱数生成:0.0f～1.0f
			/*!
			*/
			r_f32	genrand_f32p ( void );
		private:
			void	init_genrand ( r_ui32 s );
		private:
			r_ui32 mt[RMT19937AR_N];
			r_si32 mti;
			r_ui32 mag01[2];
		};
	}
}

#endif // _R_MT19937AR_H_
